// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "FoodGeneratorBase.generated.h"

DECLARE_DYNAMIC_MULTICAST_DELEGATE(FOnFoodEaten);
DECLARE_DYNAMIC_MULTICAST_DELEGATE(FOnFoodEnded);

UCLASS()
class SNAKE_API AFoodGeneratorBase : public AActor
{
	GENERATED_BODY()
	
public:	
	// Sets default values for this actor's properties
	AFoodGeneratorBase();

	UPROPERTY(EditDefaultsOnly)
	int32 FoodForWin = 10;
	
	UPROPERTY(EditDefaultsOnly);
	int32 RowCellsCount = 0;

	UPROPERTY(EditDefaultsOnly);
	int32 ColumnCellsCount = 0;

	UPROPERTY(EditDefaultsOnly);
	float CellSize = 100.f;

	UPROPERTY(BlueprintAssignable)
	FOnFoodEaten OnFoodEatenDelegate;

	UPROPERTY(BlueprintAssignable)
	FOnFoodEnded OnFoodEndedDelegate;
	
	UPROPERTY()
	TArray<class ABlockWallBase*> BlockWalls;
	
	UPROPERTY(EditDefaultsOnly)
	TSubclassOf<class AFoodItemBase> FoodItemActorClass;

	UPROPERTY()
	class ASnakeBase* SnakeActor = nullptr;
protected:
	// Called when the game starts or when spawned
	virtual void BeginPlay() override;

public:	
	// Called every frame
	virtual void Tick(float DeltaTime) override;

	UFUNCTION()
	void SetSnakeActor(ASnakeBase* Snake);

	UFUNCTION()
	void Run();

	UFUNCTION()
	void CreateFoodItem();
	
	UFUNCTION()
	TArray<FVector> GetAvailableCells();

	UFUNCTION()
	void FillAllBlockWalls();

	UFUNCTION()
	void OnFoodItemDestroyHandler(AActor* DestroyedActor);
};
